package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SensorParameters;
import com.ruoyi.system.service.ISensorParametersService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 传感器参数Controller
 * 
 * @author
 * @date 2024-04-10
 */
@Controller
@RequestMapping("/system/parameters")
public class SensorParametersController extends BaseController
{
    private String prefix = "system/parameters";

    @Autowired
    private ISensorParametersService sensorParametersService;

    @GetMapping()
    public String parameters()
    {
        return prefix + "/parameters";
    }

    /**
     * 查询传感器参数列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SensorParameters sensorParameters)
    {
        startPage();
        List<SensorParameters> list = sensorParametersService.selectSensorParametersList(sensorParameters);
        return getDataTable(list);
    }

    /**
     * 导出传感器参数列表
     */
    @Log(title = "传感器参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SensorParameters sensorParameters)
    {
        List<SensorParameters> list = sensorParametersService.selectSensorParametersList(sensorParameters);
        ExcelUtil<SensorParameters> util = new ExcelUtil<SensorParameters>(SensorParameters.class);
        return util.exportExcel(list, "传感器参数数据");
    }

    /**
     * 新增传感器参数
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存传感器参数
     */
    @Log(title = "传感器参数", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SensorParameters sensorParameters)
    {
        return toAjax(sensorParametersService.insertSensorParameters(sensorParameters));
    }

    /**
     * 修改传感器参数
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SensorParameters sensorParameters = sensorParametersService.selectSensorParametersById(id);
        mmap.put("sensorParameters", sensorParameters);
        return prefix + "/edit";
    }

    /**
     * 修改保存传感器参数
     */
    @Log(title = "传感器参数", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SensorParameters sensorParameters)
    {
        return toAjax(sensorParametersService.updateSensorParameters(sensorParameters));
    }

    /**
     * 删除传感器参数
     */
    @Log(title = "传感器参数", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sensorParametersService.deleteSensorParametersByIds(ids));
    }

    /**
     * 获取站点传感器参数详细信息
     */
    @GetMapping(value = "/getInfoBySite/{site}")
    @ResponseBody
    public AjaxResult getInfoBySite(@PathVariable("site") String site, ModelMap mmap)
    {
        return success(sensorParametersService.selectSensorParametersBySite(site));
    }

    @GetMapping(value = "/getInfo")
    @ResponseBody
    public AjaxResult getInfoBySite( ModelMap mmap)
    {
        return success(sensorParametersService.selectSensorParameters());
    }
}
